package jee.boot.entity.system;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * 查询条件
 */
public class Filter implements Serializable {
    private Object left;// 左边的表达式
    private String operate;// 操作
    private Object right;//右边的表达式
    private boolean brackets=false;//表达式是否需要括号包裹
    private boolean timestamp=false;//如果是时间戳(当前时间的毫秒数),则需要对left的表达式进行包裹

    public Filter() {
    }

    public Filter(Object left, String operate, Object right) {
        this.left = left;
        this.operate = operate;
        this.right = right;
    }

    public Object getLeft() {
        return left==null?"":left;
    }

    public void setLeft(Object left) {
        this.left = left;
    }

    public Object getRight() {
        return right==null?"":right;
    }

    public String getOperate() {
        return operate==null?"":operate;
    }

    public void setOperate(String operate) {
        this.operate = operate;
    }

    public void setRight(Object right) {
        this.right = right;
    }

    public boolean isBrackets() {
        return brackets;
    }

    public void setBrackets(boolean brackets) {
        this.brackets = brackets;
    }

    public boolean isTimestamp() {
        return timestamp;
    }

    public void setTimestamp(boolean timestamp) {
        this.timestamp = timestamp;
    }

    public Map<String, Object> toMap() {
        Map<String, Object> hashMap = new HashMap<String, Object>() {
            {
                put("left", left instanceof Filter ?((Filter) left).toMap():left);
                put("operate", operate);
                put("right", right instanceof Filter?((Filter) right).toMap():right);
                put("brackets", brackets);
            }
        };
        return hashMap;
    }
//    @Override
//    public String toString() {
//        return "("+getLeft().toString()+" " +getOperate()+" "+getRight().toString()+")";
//    }
}
